using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections.Specialized;

using DevComponents.DotNetBar;

using Settings = Pg.BioMedics.RatObserver.Gui.Properties.Settings;

namespace Pg.BioMedics.RatObserver.Gui
{
    public partial class ConfigurationForm : Office2007Form
    {
        #region Constructors

        public ConfigurationForm()
        {
            InitializeComponent();
        }

        #endregion

        #region Event handlers

        private void ConfigurationForm_Load(object sender, EventArgs e)
        {
            // diff level
            diffLevelDoubleInput.Value = Settings.Default.RotationDiffLevel;

            // movin avg filters
            string[] filters = new string[Settings.Default.RotationAvgFilters.Count];
            for (int i = 0; i < Settings.Default.RotationAvgFilters.Count; i++)
                filters[i] = Settings.Default.RotationAvgFilters[i];

            movingAvgFiltersStringListBox.Values = filters;
            regionsXIntegerInput.Value = Settings.Default.RegionsX;
            regionsYIntegerInput.Value = Settings.Default.RegionsY;
        }

        #endregion

        private void applyButton_Click(object sender, EventArgs e)
        {
            try
            {
                // copy values
                Settings.Default.RotationAvgFilters.Clear();
                for (int i = 0; i < movingAvgFiltersStringListBox.Values.Length; i++)
                    Settings.Default.RotationAvgFilters.Add(movingAvgFiltersStringListBox.Values[i]);

                Settings.Default.RotationDiffLevel = diffLevelDoubleInput.Value;
                Settings.Default.RegionsX = regionsXIntegerInput.Value;
                Settings.Default.RegionsY = regionsYIntegerInput.Value;

                // save configuration
                Settings.Default.Save();

                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception ex)
            {
                Utils.Logger.WriteError(ex);
            }
        }
    }
}